﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lizk.SimpleHUD;

namespace SharpMedia.Controls
{
    public class HUDPageHandler : HUDContainerSimple
    {
        private int currentPage = -1;
        public HUDPageHandler()
        {
        }

        public HUDPage CurrentPage
        {
            get
            {
                if (this.Count == 0)
                    return null;
                return this.Get<HUDPage>(currentPage);
            }
        }

        public void Navigate(HUDPage page)
        {
            if (currentPage >= 0)
                Get<HUDPage>(currentPage).Deactivate();
            currentPage++;
            while (currentPage < Count)
            {
                //renderer.UnloadContainer(pages[currentPage]);
                Get<HUDPage>(currentPage).Dispose();
                RemoveAt(currentPage);
            }
            Add(page);
            page.Anchor = Anchor.All;
            page.Size = Size;
            page.Show();
        }

        public void Back()
        {
            if (currentPage >= 0)
            {
                Get<HUDPage>(currentPage).Close();
            }
            currentPage--;
            if (currentPage >= 0)
                Get<HUDPage>(currentPage).Activate();
        }
    }
}
